//package com.juben.svr.demos.web;
//
//import com.itextpdf.text.Document;
//import com.itextpdf.text.Font;
//import com.itextpdf.text.Paragraph;
//import com.itextpdf.text.pdf.BaseFont;
//import com.itextpdf.text.pdf.PdfWriter;
//import com.juben.svr.domain.PdfRequest;
//import org.springframework.web.bind.annotation.PostMapping;
//import org.springframework.web.bind.annotation.RequestBody;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.RestController;
//
//import javax.servlet.http.HttpServletResponse;
//import java.io.FileOutputStream;
//import java.io.IOException;
//@RestController
//@RequestMapping("/api")
//public class PdfGenerator {
//    @PostMapping("/pdf")
//    public  void generatePdf(@RequestBody PdfRequest request, HttpServletResponse response) {
//        String text = "你好我是车是温嘉三年重建帝国和均符合";
//        Document document = new Document();
//        String outputPath = "D:\\学习资料\\毕业设计\\image\\pdfs\\example2.pdf"; // 可以改为绝对路径或动态路径
//
//        try (FileOutputStream fos = new FileOutputStream(outputPath)) {
//            PdfWriter.getInstance(document, fos); // 创建一个 PDF 文件
//            document.open();
//            // 使用支持中文的字体
//            BaseFont baseFont = BaseFont.createFont("C:\\Windows\\Fonts\\simsun.ttc,0", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
//            Font font = new Font(baseFont, 12); // 设置字体和字号
//            System.out.println(request.getText());
//            document.add(new Paragraph(request.getText(), font));
//            document.close();
//        } catch (IOException e) {
//            System.err.println("IOException occurred: " + e.getMessage());
//        } catch (Exception e) {
//            System.err.println("Exception occurred: " + e.getMessage());
//        }
//    }
//    class PdfRequest {
//        private String text;
//
//        // Getters and Setters
//        public String getText() {
//            return text;
//        }
//
//        public void setText(String text) {
//            this.text = text;
//        }
//    }
//}
